package com.leonardo.persistenceme.model.persistancehandlers;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

public class IntegerPersistanceHandler extends PersistenceHandler {
	
	public void persist(Object obj, DataOutputStream stream) throws IOException {
		if(obj == null) {
			stream.writeInt(Integer.MIN_VALUE);
			return;
		}
		Integer value = (Integer) obj;
		stream.writeInt(value.intValue());
	}

	public Object recover(DataInputStream stream) throws IOException {
		int value = stream.readInt();
		if(value == Integer.MIN_VALUE) 
			return null;
		return new Integer(value);
	}

}
